StatsD Flask
Python application
- In my python file
app.py am using the library flask_statsdclient
- I initialize Flask object called
app.
- I initialize StatsD client object calling this call -
StatsDClient(app)
- I setup STATSD_HOST=localhost, STATSD_PORT=8125, STATSD_PREFIX=statsd
- When I am creating an API endpoint, example
create_user I increment the statsd metric counter with the syntax - c.incr('register_user')
Let's see how the statsd sends metrics from app.py to AWS CloudWatch
- We have a file called - amazon-cloudwatch-agent.json
- This file includes what needs to be collected from the application - logs, metrics
- Since we are interested in metrics, which metrics are we collecting from statsd?
- Json example here
- Along with this, we are specifying the statsd config - port, collection interval and aggregation interval
- This file needs to be a specific location for the cloudwatch agent to read